var _api = _interopRequireDefault(require("../../../../../utils/api")), _common = require("../common");

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _objectSpread(e) {
    for (var t = 1; t < arguments.length; t++) {
        var i = null != arguments[t] ? arguments[t] : {}, s = Object.keys(i);
        "function" == typeof Object.getOwnPropertySymbols && (s = s.concat(Object.getOwnPropertySymbols(i).filter(function(t) {
            return Object.getOwnPropertyDescriptor(i, t).enumerable;
        }))), s.forEach(function(t) {
            _defineProperty(e, t, i[t]);
        });
    }
    return e;
}

function _defineProperty(t, e, i) {
    return e in t ? Object.defineProperty(t, e, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = i, t;
}

var LIMIT = 20, CHILD_VARIABLE = [ "track", "user", "trackInUser" ];

Component({
    properties: {
        mode: {
            type: String,
            value: "radar"
        }
    },
    created: function() {
        this.noMore = {}, this.offset = {}, this.recordLoadBar = [];
    },
    data: {
        skeleton: !0,
        lists: [ Array(8).fill({
            realname: "**",
            lastview: "**"
        }) ]
    },
    methods: {
        init: function(t) {
            this.data.skeleton && this.selectComponent("#skeleton2").create(this), this.loadUserList(!0, t);
        },
        onPullDownRefresh: function() {
            this.loadUserList(!0, wx.stopPullDownRefresh);
        },
        onReachBottom: function() {
            this.noMore[CHILD_VARIABLE[1]] || this.loadUserList(!1);
        },
        loadUserList: function(i, t) {
            var s = this, e = this.data.mode;
            i && (this.offset[CHILD_VARIABLE[1]] = 0, this.recordLoadBar.length && (this.recordLoadBar = []));
            var r = {
                type: 1,
                limit: "card" === e ? 5 : LIMIT,
                offset: this.offset[CHILD_VARIABLE[1]]
            };
            _api.default.market.log.userlists({
                data: r,
                complete: t
            }).then(function(t) {
                var e = t.data.lists;
                return s.formatVisitorUserList(i, e);
            });
        },
        formatVisitorUserList: function(t, e) {
            if (e = e.map(function(t) {
                return t.isOpen = !1, t.realname = t.desc || t.realname, t;
            }), t) this.setData({
                lists: [ e ],
                skeleton: !1
            }); else {
                var i = (this.data.lists || []).length;
                this.setData(_defineProperty({}, "lists[".concat(i, "]"), e));
            }
            this.offset[CHILD_VARIABLE[1]] += LIMIT, this.noMore[CHILD_VARIABLE[1]] = e.length < LIMIT;
        },
        gotoChat: function(t) {
            if ("card" === this.data.mode && !this.$appData.card.isFeeVer) return this.gotoRadarIndex();
            (0, _common.gochat)(t, this);
        },
        gotoRadarIndex: function() {
            this.$route("/pages/radar/index/index", "tab");
        },
        showVisitorUserLists: function(t) {
            var i = t.currentTarget.dataset.uid, e = this.data.lists, s = {};
            e.forEach(function(t) {
                if (!s || !s.uid) {
                    var e = t.find(function(t) {
                        return +t.uid == +i;
                    });
                    e && (s = e);
                }
            }), this.loadList(!0, null, i), this.setData({
                visitorUser: _objectSpread({}, s, {
                    isOpen: !0
                })
            }), this.toggleTabBar(!0);
        },
        hideVisitorUserLists: function() {
            this.setData({
                visitorUser: {
                    isOpen: !1
                }
            }), this.toggleTabBar(!1);
        },
        toggleTabBar: function(t) {
            t ? wx.hideTabBar({
                animation: !0
            }) : wx.showTabBar();
        },
        loadVisitorListInUser: function(t) {
            var e = t.currentTarget.dataset.fromuid;
            if ((this.noMore[CHILD_VARIABLE[2]] || {})[e]) return !0;
            this.loadList(!1, null, e);
        },
        loadList: function(i, t) {
            var s = this, r = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : "";
            i && (this.offset[CHILD_VARIABLE[2]] || (this.offset[CHILD_VARIABLE[2]] = {}), this.offset[CHILD_VARIABLE[2]][r] = 0), 
            _api.default.market.log.lists({
                data: {
                    fromuid: r,
                    limit: LIMIT,
                    offset: this.offset[CHILD_VARIABLE[2]][r]
                },
                complete: t
            }).then(function(t) {
                var e = t.data.lists;
                return s.formatVisitorInUser(i, (0, _common.handleVisitorLists)(e), r);
            });
        },
        formatVisitorInUser: function(t, e, i) {
            var s = (this.data.visitorUser || {
                lists: []
            }).lists;
            t ? this.setData({
                "visitorUser.lists": [ e ],
                visitorUserSkeleton: !1
            }) : this.setData(_defineProperty({}, "visitorUser.lists[".concat(s.length, "]"), e));
            var r = this.offset[CHILD_VARIABLE[2]][i];
            this.noMore[CHILD_VARIABLE[2]] || (this.noMore[CHILD_VARIABLE[2]] = {}), this.offset[CHILD_VARIABLE[2]][i] = LIMIT + r, 
            this.noMore[CHILD_VARIABLE[2]][i] = e.length < LIMIT;
        }
    }
});